#ifndef FILESYS_H
#define FILESYS_H

#include <cstdio>
#include <easyx/graphics.h>
#include "list.h"
/*
"*******************************************************"
"*                 COPYRIGHT STATEMENT                 *"
"*           THIS HEADER IS CODED BY ZEPHYRBD!         *"
"*This  header is open - sourced under the MIT License.*"
"*       Copyright 2018-2025 Minecraft ZBD Studio.     *"
"*******************************************************"
*/
void openFile(List *&head)
{
	FILE *f;
	f = fopen("data.txt","r");
	if(f==NULL) 
	{
		MessageBox(NULL, "无有效文件，正在创建...", "提示", MB_ICONINFORMATION | MB_OK);
		f = fopen("data.txt","w");
	}
	List tmp;
	while(fscanf(f,"%d %s %d %d %d %d %s %s",&tmp.id,tmp.name,&tmp.sex,&tmp.age,&tmp.money,&tmp.college,tmp.address,tmp.tel)==8)
	{
		insertList(tmp,head);
	}
	fclose(f);
}

void writeFile(List *head)
{
	FILE *f;
	f = fopen("data.txt","w");
	List *p=head;
	while(p!=NULL)
	{
		List tmp = *p;
		fprintf(f,"%010d %s %d %d %d %02d %s %s\n",tmp.id,tmp.name,tmp.sex,tmp.age,tmp.money,tmp.college,tmp.address,tmp.tel);
		p = p->next;
	}
	fclose(f);
}
#endif
